import pytest,time
from selenium import webdriver

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

@pytest.fixture
def driver():
    driver = webdriver.Edge()
    driver.get('http://10.59.9.12:7001/')
    yield driver
    time.sleep(3)
    driver.quit()

def test_01(driver):
    driver.find_element(By.XPATH, '//a[@href="/home/login.html"]').click()
    time.sleep(3)
    dy1 = driver.find_element(By.CLASS_NAME, 'reg-new').text
    print("断言1:", dy1)
    driver.find_element(By.NAME, 'username').send_keys('15235688537')
    driver.find_element(By.NAME, 'password').send_keys('a123123')
    time.sleep(10)
    driver.find_element(By.XPATH, '//*[@id="theForm"]/div[5]/a').click()
    time.sleep(3)
    # 搜索
    driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/ul/li[1]/a').click()
    time.sleep(2)
    search = driver.find_element(By.CLASS_NAME, 'search-input')
    search.send_keys('非洲之心')
    time.sleep(3)
    search.send_keys(Keys.ENTER)
    time.sleep(3)
    dy3 = driver.find_element(By.XPATH, '/html/body/div[4]/a[2]').text
    print("断言3:", dy3)
    driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img').click()
    driver.find_element(By.ID, 'buy-cart').click()
    time.sleep(3)
    dy4 = driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/a[2]').text
    print("断言4:", dy4)
    driver.find_element(By.CLASS_NAME, 'radio-select-btn').click()
    driver.find_element(By.ID, 'order-button').click()
    time.sleep(5)
    dy5 = driver.find_element(By.XPATH, '/html/body/div[4]/div[3]/span').text
    print("断言5:", dy5)